<?php 

require_once('functions/session.php');
require_once('functions/functions.php');

// -------- BEGIN: FORM INPUT VALIDATION --------- //

if (!isset($_SESSION['Q1_ID'])) {
	// Validate input, and if correct, set $_SESSION['Q1_ID']
	validate_q1_form();
}

if ((isset($_SESSION['Q1_ID'])) && (!isset($_SESSION['username']))) {
	// Validate input, and if correct, set $_SESSION['username']
	validate_user_account_form();
}

// Redirect to home page if sign-up already completed
if (isset($_SESSION['username'])) {
	header("location: index.php");
	exit();
}

// -------- END: FORM INPUT VALIDATION --------- //

include 'header.php';

// --- STEP 1 : Fill in Questionnaire 1 --- //
	// If Questionnaire 1 hasn't been (correctly) filled in, display it
if (!isset($_SESSION['Q1_ID']))
	include 'q1.php';


// --- STEP 2 : Create user account --- //
if (isset($_SESSION['Q1_ID'])) {
	if (!(isset($_SESSION['username']))) {
?>

<div id="stylized" class="myform">
	<form id="sign_up_form" name="sign_up_form" action="sign_up.php" method="POST">
		<p>[Step 1: Survey] <b>[Step 2: Create account]</b></p>
		
		<label>Username
		</label>
		<input type="text" name="U[username]" value="<?php echo $zU['username'] ?>" />
		
		<label>Password
		</label>
		<input type="password" name="U[password]" value="<?php echo $zU['password'] ?>" />
				
		<label>Confirm password
		</label>
		<input type="password" name="U[password_c]" value="<?php echo $zU['password_c'] ?>" />
		
		<button type="submit">Done!</button>
		<div class="spacer"></div>
		
		<?php 
		if ($U_validation_errors)
			print '<div class="errors">'.$U_validation_errors.'</div>';
		?>
		
		
	</form>
</div>

<?php 
	}
}

include 'footer.php';

?>